package com.jcl.recruit.console.user.logic;

import com.jcl.core.utils.CollectionUtils;
import com.jcl.recruit.console.user.dao.SysUserDao;
import com.jcl.recruit.console.user.model.SysUser;
import com.jcl.recruit.console.user.model.vo.SysUserVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName ConsoleUserLogic
 * @Author yyliu
 * @Date 2018/12/20 18:38
 * @Version 1.0
 **/
@Component
public class ConsoleUserLogic {

    @Autowired
    private SysUserDao sysUserDao;


    public List<SysUser> findList() {
        return sysUserDao.findList();
    }

    public List<SysUserVo> constractUserList(List<SysUser> list) {

        List<SysUserVo> voList = new ArrayList<>();
        if (CollectionUtils.isNotEmpty(list)) {
            for (SysUser user : list) {
                SysUserVo vo = constractUser(user);
                voList.add(vo);
            }
        }
        return voList;
    }

    public SysUserVo constractUser(SysUser user) {

        SysUserVo vo = new SysUserVo();
        BeanUtils.copyProperties(user, vo);
        return vo;
    }

    public SysUser findOneById(Integer id) {
        return sysUserDao.findOneById(id);
    }

    public SysUser findOne(String username) {
        return sysUserDao.findOne(username);
    }

    public int insert(SysUser entity) {
        return sysUserDao.insert(entity);
    }

    public int update(SysUser entity) {
        return sysUserDao.update(entity);
    }

    public int updatePw(Integer id, String password) {
        return sysUserDao.updatePw(id, password);
    }

    public int delete(Integer id) {
        return sysUserDao.delete(id);
    }

}
